<include file='Index/header' />
<div class="row">
	<br>
	<div class="col-sm-12">
		<div class="col-sm-2"></div>
		<div class="col-sm-1" style="padding-top:5px;width:120px">
			<label class="control-label">入库日期：</label>
		</div>
		<div class="col-sm-3">
			<input id="start_date" class="form-control"></input>
		</div>
		<div class="col-sm-1" style="padding-top:5px;width:10px">至</div>
		<div class="col-sm-3">
			<input id="end_date" class="form-control"></input>
		</div>
	</div>
	<div class="col-sm-12">
		<br>
		<div class="col-sm-2">
			<ul id="repository_tree" class="ztree"></ul>
		</div>
		<div class="col-sm-10">
			<table id="admin_list_table" class="table table-hover table-bordered table-striped table-striped">
				<thead>
					<tr>
						<td>A仓库</td>
						<td>B仓库</td>
						<td>入库单流水号</td>
						<td>商品名称</td>
						<td>条形码货号</td>
						<td>快驹售价</td>
						<td>入库量</td>
						<td>结余库存</td>
						<td>入库日期</td>
						<td>操作人</td>
						<td>操作日志</td>
					</tr>
				</thead>
				<tbody>

				</tbody>
			</table>
		</div>
	</div>
</div>
<include file='Index/footer' />
<script>
$(document).ready(function() {
	loadDatetimepicker('start_date');
	loadDatetimepicker('end_date');
	loadRepositoryTree('repository_tree', true);
	loadTable();
});


var table;
function loadTable(){
	var data = '{$data}';
	data = eval(data);

	table = $('#admin_list_table').DataTable({
		"bProcessing": true,
		"bDestroy": true,
		"sPaginationType" : "input",
		"oLanguage" : {
              "sLengthMenu": "每页显示 _MENU_ 条记录",
              "sZeroRecords": "抱歉， 没有找到",
              "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
              "sInfoEmpty": "没有数据",
              "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
              "sZeroRecords": "没有检索到数据",
               "sSearch": "搜索: &nbsp",
              "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
              }
          }, 
		"data" : data,
		"columns": [
					{ "data": 'a_repository_id' },
					{ "data": 'b_repository_id' },
					{ "data": 'admin_repository_id' },
					{ "data": 'name' },
	        { "data": 'barcode' },
	        { "data": 'kj_price' },
	        { "data": 'add_amount' },
	        { "data": 'remain_amount' },
	        { "data": 'createtime' },
	        { "data": 'admin' },
	        { "data": 'note' }
    ],
    "columnDefs": [
			{
				"targets":[0, 1],
				"visible":false
			},
   ]
	});

	$.fn.dataTable.ext.search.push(
	    function( settings, data, dataIndex ) {
	        var min = new Date($('#start_date').val());
	        var max = new Date($('#end_date').val());
	        var now = new Date( data[8] ); 

	        if ( ( isNaN( min ) && isNaN( max ) ) ||
	             ( isNaN( min ) && now <= max ) ||
	             ( min <= now   && isNaN( max ) ) ||
	             ( min <= now   && now <= max ) )
	        {
	            return true;
	        }
	        return false;
	    }
	);	

	$('#start_date, #end_date').datetimepicker().on('changeDate', function(e){
      table.draw();
  });
}


function searchARepository(val){
	table.column(0).search('').draw();
	table.column(1).search('').draw();
	table.column(0).search(val).draw();
}

function searchBRepository(val){
	table.column(0).search('').draw();
	table.column(1).search('').draw();
	table.column(1).search(val).draw();
}
</script>
